package com.ruoyi.wm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wm.domain.WmApparatus;
import com.ruoyi.wm.service.IWmApparatusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 耗材列Controller
 * 
 * @author hpf
 * @date 2021-12-03
 */
@Controller
@RequestMapping("/wm/wm_apparatus")
public class WmApparatusController extends BaseController
{
    private String prefix = "wm/wm_apparatus";

    @Autowired
    private IWmApparatusService wmApparatusService;

    @RequiresPermissions("wm:wm_apparatus:view")
    @GetMapping()
    public String wm_apparatus()
    {
        return prefix + "/wm_apparatus";
    }

    /**
     * 查询耗材列列表
     */
    @RequiresPermissions("wm:wm_apparatus:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmApparatus wmApparatus)
    {
        startPage();
        List<WmApparatus> list = wmApparatusService.selectWmApparatusList(wmApparatus);
        return getDataTable(list);
    }

    /**
     * 导出耗材列列表
     */
    @RequiresPermissions("wm:wm_apparatus:export")
    @Log(title = "耗材列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmApparatus wmApparatus)
    {
        List<WmApparatus> list = wmApparatusService.selectWmApparatusList(wmApparatus);
        ExcelUtil<WmApparatus> util = new ExcelUtil<WmApparatus>(WmApparatus.class);
        return util.exportExcel(list, "wm_apparatus");
    }

    /**
     * 新增耗材列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存耗材列
     */
    @RequiresPermissions("wm:wm_apparatus:add")
    @Log(title = "耗材列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmApparatus wmApparatus)
    {
        return toAjax(wmApparatusService.insertWmApparatus(wmApparatus));
    }

    /**
     * 修改耗材列
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        WmApparatus wmApparatus = wmApparatusService.selectWmApparatusById(id);
        mmap.put("wmApparatus", wmApparatus);
        return prefix + "/edit";
    }

    /**
     * 修改保存耗材列
     */
    @RequiresPermissions("wm:wm_apparatus:edit")
    @Log(title = "耗材列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmApparatus wmApparatus)
    {
        return toAjax(wmApparatusService.updateWmApparatus(wmApparatus));
    }

    /**
     * 删除耗材列
     */
    @RequiresPermissions("wm:wm_apparatus:remove")
    @Log(title = "耗材列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmApparatusService.deleteWmApparatusByIds(ids));
    }
}
